﻿#region Using directives

using System;
using System.Data;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using NetROS.Tiers.Entities;
using NetROS.Tiers.Data;

#endregion

namespace NetROS.Tiers.Data.Bases
{	
	///<summary>
	/// This class is the base class for any <see cref="VwBankaProviderBase"/> implementation.
	/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
	///</summary>
	public abstract class VwBankaProviderBaseCore : EntityViewProviderBase<VwBanka>
	{
		#region Custom Methods
		
		
		#endregion

		#region Helper Functions
		
		/*
		///<summary>
		/// Fill an VList&lt;VwBanka&gt; From a DataSet
		///</summary>
		/// <param name="dataSet">the DataSet</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pagelen">number of row.</param>
		///<returns><see chref="VList&lt;VwBanka&gt;"/></returns>
		protected static VList&lt;VwBanka&gt; Fill(DataSet dataSet, VList<VwBanka> rows, int start, int pagelen)
		{
			if (dataSet.Tables.Count == 1)
			{
				return Fill(dataSet.Tables[0], rows, start, pagelen);
			}
			else
			{
				return new VList<VwBanka>();
			}	
		}
		
		
		///<summary>
		/// Fill an VList&lt;VwBanka&gt; From a DataTable
		///</summary>
		/// <param name="dataTable">the DataTable that hold the data.</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pagelen">number of row.</param>
		///<returns><see chref="VList<VwBanka>"/></returns>
		protected static VList&lt;VwBanka&gt; Fill(DataTable dataTable, VList<VwBanka> rows, int start, int pagelen)
		{
			int recordnum = 0;
			
			System.Collections.IEnumerator dataRows =  dataTable.Rows.GetEnumerator();
			
			while (dataRows.MoveNext() && (pagelen != 0))
			{
				if(recordnum >= start)
				{
					DataRow row = (DataRow)dataRows.Current;
				
					VwBanka c = new VwBanka();
					c.Naziv = (Convert.IsDBNull(row["Naziv"]))?string.Empty:(System.String)row["Naziv"];
					c.MB = (Convert.IsDBNull(row["MB"]))?string.Empty:(System.String)row["MB"];
					c.MinimalniIznos = (Convert.IsDBNull(row["MinimalniIznos"]))?0:(System.Decimal?)row["MinimalniIznos"];
					c.MaksimalniIznos = (Convert.IsDBNull(row["MaksimalniIznos"]))?0:(System.Decimal?)row["MaksimalniIznos"];
					c.MaksimalniBrojRata = (Convert.IsDBNull(row["MaksimalniBrojRata"]))?(int)0:(System.Int32?)row["MaksimalniBrojRata"];
					c.Mjesto = (Convert.IsDBNull(row["Mjesto"]))?string.Empty:(System.String)row["Mjesto"];
					c.PostanskiBroj = (Convert.IsDBNull(row["PostanskiBroj"]))?(int)0:(System.Int32?)row["PostanskiBroj"];
					c.SifraOpcine = (Convert.IsDBNull(row["SifraOpcine"]))?(int)0:(System.Int32?)row["SifraOpcine"];
					c.Prirez = (Convert.IsDBNull(row["Prirez"]))?0.0F:(System.Single?)row["Prirez"];
					c.ZiroRacunZaPorezPrirez = (Convert.IsDBNull(row["ZiroRacunZaPorezPrirez"]))?string.Empty:(System.String)row["ZiroRacunZaPorezPrirez"];
					c.TipMjesta = (Convert.IsDBNull(row["TipMjesta"]))?(int)0:(System.Int32?)row["TipMjesta"];
					c.ID = (Convert.IsDBNull(row["ID"]))?(int)0:(System.Int32)row["ID"];
					c.VodeciBrojDepozitneIstitucije = (Convert.IsDBNull(row["VodeciBrojDepozitneIstitucije"]))?(int)0:(System.Int32)row["VodeciBrojDepozitneIstitucije"];
					c.AcceptChanges();
					rows.Add(c);
					pagelen -= 1;
				}
				recordnum += 1;
			}
			return rows;
		}
		*/	
						
		///<summary>
		/// Fill an <see cref="VList&lt;VwBanka&gt;"/> From a DataReader.
		///</summary>
		/// <param name="reader">Datareader</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pageLength">number of row.</param>
		///<returns>a <see cref="VList&lt;VwBanka&gt;"/></returns>
		protected VList<VwBanka> Fill(IDataReader reader, VList<VwBanka> rows, int start, int pageLength)
		{
			int recordnum = 0;
			while (reader.Read() && (pageLength != 0))
			{
				if(recordnum >= start)
				{
					VwBanka entity = null;
					if (DataRepository.Provider.UseEntityFactory)
					{
						entity = EntityManager.CreateViewEntity<VwBanka>("VwBanka",  DataRepository.Provider.EntityCreationalFactoryType); 
					}
					else
					{
						entity = new VwBanka();
					}
					entity.Naziv = (System.String)reader["Naziv"];
					//entity.Naziv = (Convert.IsDBNull(reader["Naziv"]))?string.Empty:(System.String)reader["Naziv"];
					entity.MB = reader.IsDBNull(reader.GetOrdinal("MB")) ? null : (System.String)reader["MB"];
					//entity.MB = (Convert.IsDBNull(reader["MB"]))?string.Empty:(System.String)reader["MB"];
					entity.MinimalniIznos = reader.IsDBNull(reader.GetOrdinal("MinimalniIznos")) ? null : (System.Decimal?)reader["MinimalniIznos"];
					//entity.MinimalniIznos = (Convert.IsDBNull(reader["MinimalniIznos"]))?0:(System.Decimal?)reader["MinimalniIznos"];
					entity.MaksimalniIznos = reader.IsDBNull(reader.GetOrdinal("MaksimalniIznos")) ? null : (System.Decimal?)reader["MaksimalniIznos"];
					//entity.MaksimalniIznos = (Convert.IsDBNull(reader["MaksimalniIznos"]))?0:(System.Decimal?)reader["MaksimalniIznos"];
					entity.MaksimalniBrojRata = reader.IsDBNull(reader.GetOrdinal("MaksimalniBrojRata")) ? null : (System.Int32?)reader["MaksimalniBrojRata"];
					//entity.MaksimalniBrojRata = (Convert.IsDBNull(reader["MaksimalniBrojRata"]))?(int)0:(System.Int32?)reader["MaksimalniBrojRata"];
					entity.Mjesto = reader.IsDBNull(reader.GetOrdinal("Mjesto")) ? null : (System.String)reader["Mjesto"];
					//entity.Mjesto = (Convert.IsDBNull(reader["Mjesto"]))?string.Empty:(System.String)reader["Mjesto"];
					entity.PostanskiBroj = reader.IsDBNull(reader.GetOrdinal("PostanskiBroj")) ? null : (System.Int32?)reader["PostanskiBroj"];
					//entity.PostanskiBroj = (Convert.IsDBNull(reader["PostanskiBroj"]))?(int)0:(System.Int32?)reader["PostanskiBroj"];
					entity.SifraOpcine = reader.IsDBNull(reader.GetOrdinal("SifraOpcine")) ? null : (System.Int32?)reader["SifraOpcine"];
					//entity.SifraOpcine = (Convert.IsDBNull(reader["SifraOpcine"]))?(int)0:(System.Int32?)reader["SifraOpcine"];
					entity.Prirez = reader.IsDBNull(reader.GetOrdinal("Prirez")) ? null : (System.Single?)reader["Prirez"];
					//entity.Prirez = (Convert.IsDBNull(reader["Prirez"]))?0.0F:(System.Single?)reader["Prirez"];
					entity.ZiroRacunZaPorezPrirez = reader.IsDBNull(reader.GetOrdinal("ZiroRacunZaPorezPrirez")) ? null : (System.String)reader["ZiroRacunZaPorezPrirez"];
					//entity.ZiroRacunZaPorezPrirez = (Convert.IsDBNull(reader["ZiroRacunZaPorezPrirez"]))?string.Empty:(System.String)reader["ZiroRacunZaPorezPrirez"];
					entity.TipMjesta = reader.IsDBNull(reader.GetOrdinal("TipMjesta")) ? null : (System.Int32?)reader["TipMjesta"];
					//entity.TipMjesta = (Convert.IsDBNull(reader["TipMjesta"]))?(int)0:(System.Int32?)reader["TipMjesta"];
					entity.ID = (System.Int32)reader["ID"];
					//entity.ID = (Convert.IsDBNull(reader["ID"]))?(int)0:(System.Int32)reader["ID"];
					entity.VodeciBrojDepozitneIstitucije = (System.Int32)reader["VodeciBrojDepozitneIstitucije"];
					//entity.VodeciBrojDepozitneIstitucije = (Convert.IsDBNull(reader["VodeciBrojDepozitneIstitucije"]))?(int)0:(System.Int32)reader["VodeciBrojDepozitneIstitucije"];
					entity.AcceptChanges();
					rows.Add(entity);
					pageLength -= 1;
				}
				recordnum += 1;
			}
			return rows;
		}
		
		
		/// <summary>
		/// Refreshes the <see cref="VwBanka"/> object from the <see cref="IDataReader"/>.
		/// </summary>
		/// <param name="reader">The <see cref="IDataReader"/> to read from.</param>
		/// <param name="entity">The <see cref="VwBanka"/> object to refresh.</param>
		protected void RefreshEntity(IDataReader reader, VwBanka entity)
		{
			reader.Read();
			entity.Naziv = (System.String)reader["Naziv"];
			//entity.Naziv = (Convert.IsDBNull(reader["Naziv"]))?string.Empty:(System.String)reader["Naziv"];
			entity.MB = reader.IsDBNull(reader.GetOrdinal("MB")) ? null : (System.String)reader["MB"];
			//entity.MB = (Convert.IsDBNull(reader["MB"]))?string.Empty:(System.String)reader["MB"];
			entity.MinimalniIznos = reader.IsDBNull(reader.GetOrdinal("MinimalniIznos")) ? null : (System.Decimal?)reader["MinimalniIznos"];
			//entity.MinimalniIznos = (Convert.IsDBNull(reader["MinimalniIznos"]))?0:(System.Decimal?)reader["MinimalniIznos"];
			entity.MaksimalniIznos = reader.IsDBNull(reader.GetOrdinal("MaksimalniIznos")) ? null : (System.Decimal?)reader["MaksimalniIznos"];
			//entity.MaksimalniIznos = (Convert.IsDBNull(reader["MaksimalniIznos"]))?0:(System.Decimal?)reader["MaksimalniIznos"];
			entity.MaksimalniBrojRata = reader.IsDBNull(reader.GetOrdinal("MaksimalniBrojRata")) ? null : (System.Int32?)reader["MaksimalniBrojRata"];
			//entity.MaksimalniBrojRata = (Convert.IsDBNull(reader["MaksimalniBrojRata"]))?(int)0:(System.Int32?)reader["MaksimalniBrojRata"];
			entity.Mjesto = reader.IsDBNull(reader.GetOrdinal("Mjesto")) ? null : (System.String)reader["Mjesto"];
			//entity.Mjesto = (Convert.IsDBNull(reader["Mjesto"]))?string.Empty:(System.String)reader["Mjesto"];
			entity.PostanskiBroj = reader.IsDBNull(reader.GetOrdinal("PostanskiBroj")) ? null : (System.Int32?)reader["PostanskiBroj"];
			//entity.PostanskiBroj = (Convert.IsDBNull(reader["PostanskiBroj"]))?(int)0:(System.Int32?)reader["PostanskiBroj"];
			entity.SifraOpcine = reader.IsDBNull(reader.GetOrdinal("SifraOpcine")) ? null : (System.Int32?)reader["SifraOpcine"];
			//entity.SifraOpcine = (Convert.IsDBNull(reader["SifraOpcine"]))?(int)0:(System.Int32?)reader["SifraOpcine"];
			entity.Prirez = reader.IsDBNull(reader.GetOrdinal("Prirez")) ? null : (System.Single?)reader["Prirez"];
			//entity.Prirez = (Convert.IsDBNull(reader["Prirez"]))?0.0F:(System.Single?)reader["Prirez"];
			entity.ZiroRacunZaPorezPrirez = reader.IsDBNull(reader.GetOrdinal("ZiroRacunZaPorezPrirez")) ? null : (System.String)reader["ZiroRacunZaPorezPrirez"];
			//entity.ZiroRacunZaPorezPrirez = (Convert.IsDBNull(reader["ZiroRacunZaPorezPrirez"]))?string.Empty:(System.String)reader["ZiroRacunZaPorezPrirez"];
			entity.TipMjesta = reader.IsDBNull(reader.GetOrdinal("TipMjesta")) ? null : (System.Int32?)reader["TipMjesta"];
			//entity.TipMjesta = (Convert.IsDBNull(reader["TipMjesta"]))?(int)0:(System.Int32?)reader["TipMjesta"];
			entity.ID = (System.Int32)reader["ID"];
			//entity.ID = (Convert.IsDBNull(reader["ID"]))?(int)0:(System.Int32)reader["ID"];
			entity.VodeciBrojDepozitneIstitucije = (System.Int32)reader["VodeciBrojDepozitneIstitucije"];
			//entity.VodeciBrojDepozitneIstitucije = (Convert.IsDBNull(reader["VodeciBrojDepozitneIstitucije"]))?(int)0:(System.Int32)reader["VodeciBrojDepozitneIstitucije"];
			reader.Close();
	
			entity.AcceptChanges();
		}
		
		/*
		/// <summary>
		/// Refreshes the <see cref="VwBanka"/> object from the <see cref="DataSet"/>.
		/// </summary>
		/// <param name="dataSet">The <see cref="DataSet"/> to read from.</param>
		/// <param name="entity">The <see cref="VwBanka"/> object.</param>
		protected static void RefreshEntity(DataSet dataSet, VwBanka entity)
		{
			DataRow dataRow = dataSet.Tables[0].Rows[0];
			
			entity.Naziv = (Convert.IsDBNull(dataRow["Naziv"]))?string.Empty:(System.String)dataRow["Naziv"];
			entity.MB = (Convert.IsDBNull(dataRow["MB"]))?string.Empty:(System.String)dataRow["MB"];
			entity.MinimalniIznos = (Convert.IsDBNull(dataRow["MinimalniIznos"]))?0:(System.Decimal?)dataRow["MinimalniIznos"];
			entity.MaksimalniIznos = (Convert.IsDBNull(dataRow["MaksimalniIznos"]))?0:(System.Decimal?)dataRow["MaksimalniIznos"];
			entity.MaksimalniBrojRata = (Convert.IsDBNull(dataRow["MaksimalniBrojRata"]))?(int)0:(System.Int32?)dataRow["MaksimalniBrojRata"];
			entity.Mjesto = (Convert.IsDBNull(dataRow["Mjesto"]))?string.Empty:(System.String)dataRow["Mjesto"];
			entity.PostanskiBroj = (Convert.IsDBNull(dataRow["PostanskiBroj"]))?(int)0:(System.Int32?)dataRow["PostanskiBroj"];
			entity.SifraOpcine = (Convert.IsDBNull(dataRow["SifraOpcine"]))?(int)0:(System.Int32?)dataRow["SifraOpcine"];
			entity.Prirez = (Convert.IsDBNull(dataRow["Prirez"]))?0.0F:(System.Single?)dataRow["Prirez"];
			entity.ZiroRacunZaPorezPrirez = (Convert.IsDBNull(dataRow["ZiroRacunZaPorezPrirez"]))?string.Empty:(System.String)dataRow["ZiroRacunZaPorezPrirez"];
			entity.TipMjesta = (Convert.IsDBNull(dataRow["TipMjesta"]))?(int)0:(System.Int32?)dataRow["TipMjesta"];
			entity.ID = (Convert.IsDBNull(dataRow["ID"]))?(int)0:(System.Int32)dataRow["ID"];
			entity.VodeciBrojDepozitneIstitucije = (Convert.IsDBNull(dataRow["VodeciBrojDepozitneIstitucije"]))?(int)0:(System.Int32)dataRow["VodeciBrojDepozitneIstitucije"];
			entity.AcceptChanges();
		}
		*/
			
		#endregion Helper Functions
	}//end class

	#region VwBankaFilterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="SqlFilterBuilder&lt;EntityColumn&gt;"/> class
	/// that is used exclusively with a <see cref="VwBanka"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class VwBankaFilterBuilder : SqlFilterBuilder<VwBankaColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the VwBankaFilterBuilder class.
		/// </summary>
		public VwBankaFilterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the VwBankaFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public VwBankaFilterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the VwBankaFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public VwBankaFilterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion VwBankaFilterBuilder

	#region VwBankaParameterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="ParameterizedSqlFilterBuilder&lt;EntityColumn&gt;"/> class
	/// that is used exclusively with a <see cref="VwBanka"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class VwBankaParameterBuilder : ParameterizedSqlFilterBuilder<VwBankaColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the VwBankaParameterBuilder class.
		/// </summary>
		public VwBankaParameterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the VwBankaParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public VwBankaParameterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the VwBankaParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public VwBankaParameterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion VwBankaParameterBuilder
} // end namespace
